//
//  ImageDownloadHelper.m
//  WoWeibo
//
//  Created by Jaedong n.Die_ on 12-5-31.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ImageDownloadHelper.h"

#import "ImageDownloadOperation.h"

@implementation ImageDownloadHelper

@synthesize maxConcurrentCount = _maxConcurrentCount;

- (id)init {

    self = [super init];
    if(self) {
    
        _imageDownloadQueue = [[NSOperationQueue alloc] init];
        _maxConcurrentCount = 10;
        _imageDownloadQueue.maxConcurrentOperationCount = _maxConcurrentCount;
    }
    
    return self;
}

- (void)setMaxConcurrentCount:(NSInteger)maxConcurrentCount {

    _maxConcurrentCount = maxConcurrentCount;
    
    _imageDownloadQueue.maxConcurrentOperationCount = _maxConcurrentCount;
}

- (void)downloadImageWithURL:(NSURL *)imageURL fromTarget:(id<ImageDownloadOperationDelegate>)target {

    assert(imageURL != nil);
    assert(target != nil);
    
    ImageDownloadOperation *operation = [[ImageDownloadOperation alloc] initWithURL:imageURL];
    operation.delegate = target;
    [_imageDownloadQueue addOperation:operation];
    [operation release];
}

- (void)dealloc {

    [_imageDownloadQueue release];
    
    _imageDownloadQueue = nil;
    
    [super dealloc];
}

@end
